#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<random>
#include<algorithm>
#define N 30
#define M 1000000
using namespace std;
const int inf=(int)(1e9);
mt19937 RAND(random_device{}());
const int sx[4]={1,-1,0,0};
const int sy[4]={0,0,1,-1};
const char cs[3]={'R','G','B'};
char rst[M+1],c[N+1][N+1];
int x,y,minn,p[4];
bool check(int x,int y)
{
	return 1<=x&&x<=N&&1<=y&&y<=N;
}
int calc(int x,int y)
{
	return max(abs(x-(N>>1)),abs(y-(N>>1)));
}
int main()
{
	char d;
	int res,ds;
	x=y=N>>1,res=1000001;
	for (int i=1;i<=N;++i)
		for (int j=1;j<=N;++j)
		{
			if (!((i+j)&1)) c[i][j]=cs[((((j-1)>>1)-(i-1))%3+3)%3];
			else c[i][j]=cs[((((N-j)>>1)-(i-1))%3+3)%3];
		}
	int scnt=0;
	while (1)
	{
		scnt++;
		for (int i=1;i<=1000000;++i) rst[i]=cs[RAND()%3];
		for (int i=1;i<=1000000;++i)
		{
			d=rst[i],minn=inf,ds=0;
			for (int j=0;j<=3;++j)
				if (check(x+sx[j],y+sy[j])&&c[x+sx[j]][y+sy[j]]==d&&calc(x+sx[j],y+sy[j])<minn)
					minn=calc(x+sx[j],y+sy[j]),ds=j;
			if (minn==inf)
			{
				res=i;
				cerr<<scnt<<'#'<<1/0<<endl;
				break;
			}
			x+=sx[ds],y+=sy[ds];
		}
	}
	return 0;
}
